package com.ctshk.sapp.goods.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.goods.dto.ShoppingShopDTO;
import com.ctshk.rpc.goods.dto.ShoppingShopKeyWordsDTO;
import com.ctshk.rpc.goods.req.ShoppingShopAddReq;
import com.ctshk.rpc.goods.req.ShoppingShopPageReq;
import com.ctshk.rpc.goods.req.ShoppingShopUpdateStatusReq;
import com.ctshk.rpc.goods.service.IShoppingShopKeyWordService;
import com.ctshk.rpc.goods.service.IShoppingShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商城管理 前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-06

 */
@Api(value="商城管理", tags="商城管理")
@RestController
@RequestMapping("/shoppingShop")
public class ShoppingShopController extends BaseController {
    @DubboReference
    private IShoppingShopService shoppingShopService;

    @ApiOperation(value = "新增商城", notes = "新增商城")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增商城", operDesc = "新增商城")
    @PostMapping("/addShoppingShop")
    public Result addShoppingShop(@RequestBody @Valid ShoppingShopAddReq obj) {
    	shoppingShopService.addShoppingShop(obj, getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    
    @ApiOperation(value = "编辑商城", notes = "编辑商城")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑商城", operDesc = "编辑商城")
    @PostMapping("/updateShoppingShop")
    public Result updateShoppingShop(@RequestBody @Valid ShoppingShopAddReq obj) {
    	shoppingShopService.updateShoppingShop(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    
    @ApiOperation(value = "编辑商城状态", notes = "编辑商城状态")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑商城状态", operDesc = "编辑商城状态")
    @PostMapping("/updateShoppingShopStatus")
    public Result updateShoppingShop(@RequestBody @Valid ShoppingShopUpdateStatusReq obj) {
    	shoppingShopService.updateShoppingShopStatus(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "分页查询商城管理", notes = "分页查询商城管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "分页查询商城管理", operDesc = "分页查询商城管理")
    @PostMapping("/findPageList")
    public Result<PageResponse<ShoppingShopDTO>> queryList(@RequestBody ShoppingShopPageReq pageReq) {
        PageResponse<ShoppingShopDTO> response = shoppingShopService.findShoppingShopByAll(pageReq,getCurrentUser(getRequest()));
        return Result.success(response);
    }
    
    @ApiOperation(value = "商城下拉列表", notes = "商城下拉列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "商城下拉列表", operDesc = "商城下拉列表")
    @GetMapping("/findShoppingShopNameList/{menuId}")
    public Result<List<ShoppingShopDTO>> findShoppingShopNameList(@PathVariable("menuId") Long menuId) {
    	List<ShoppingShopDTO> response = shoppingShopService.findShoppingShopNameList(menuId, getCurrentUser(getRequest()));
        return Result.success(response);
    }

    @ApiOperation(value = "根据ID查询商城详情", notes = "根据ID查询商城详情")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "根据ID查询商城详情", operDesc = "根据ID查询商城详情")
    @GetMapping("/findShoppingShopInfoById/{id}")
    public Result<ShoppingShopDTO> findShoppingShopInfoById(@PathVariable("id") Long id) {
        ShoppingShopDTO shoppingShopDTO = shoppingShopService.findShoppingShopInfoById(id);
        return Result.success(shoppingShopDTO);
    }
}
